Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create static file collections #110

Merged
merged 35 commits into from
Jun 25, 2022
Merged

Conversation

caendesilva
Copy link
Member

About

Not sure if this is the best name for it, but this update adds a DataCollection module (which may me merged into the core as it became much simpler than I expected), which reads flatfile content and parses them into usable Laravel collections.

Currently only a Markdown collection type is added. This is easel accessible with the MarkdownCollection facade that is made available to Blade views through the DataCollectionServiceProvider.

Supply the name for a subdirectory of the new _data directory to the facade to get a collection with the parsed files.

Example usage

For example, imagine we have a directory called _data/testimonials where we collect testimonials in the form of Markdown files, with front matter to specify the author and link.

// filepath: _data/testimonials/one.md
---
author: John Doe
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit...

We can then use the MarkdownCollection facade

MarkdownCollection::get('testimonials')

To get the testimonials in a Blade view

@foreach(MarkdownCollection::get('testimonials') as $testimonial)
<blockquote>
    <p>{!! $testimonial->body !!}</p>
    <small>{{ $testimonial->matter['author'] }}</small>
</blockquote>
@endforeach

Rendered result

And if we take a look at the data dump, you'll see that the Markdown files are rendered into the MarkdownDocument object model, same as all Markdown based pages in Hyde.
Data dump

@codecov
Copy link

codecov bot commented Jun 25, 2022

Codecov Report

Merging #110 (a84edbe) into master (451a84d) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #110      +/-   ##
============================================
+ Coverage     98.91%   98.92%   +0.01%     
- Complexity      741      752      +11     
============================================
  Files            95       98       +3     
  Lines          1930     1958      +28     
============================================
+ Hits           1909     1937      +28     
  Misses           21       21              
Impacted Files Coverage Δ
packages/framework/src/HydeServiceProvider.php 94.28% <100.00%> (+0.53%) ⬆️
...ork/src/Modules/DataCollections/DataCollection.php 100.00% <100.00%> (ø)
.../DataCollections/DataCollectionServiceProvider.php 100.00% <100.00%> (ø)
...les/DataCollections/Facades/MarkdownCollection.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 451a84d...a84edbe. Read the comment docs.

@caendesilva caendesilva marked this pull request as ready for review June 25, 2022 11:42
@caendesilva caendesilva merged commit c7ffb61 into master Jun 25, 2022
@caendesilva caendesilva deleted the create-static-file-collections branch June 25, 2022 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants